package com.cy.stone.system.domain.clientobject.dict;

import com.cy.stone.common.base.AddGroup;
import com.cy.stone.common.base.EditGroup;
import com.cy.stone.system.infrastructure.database.entity.DictDataEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;

/**
 * 字典数据入参
 * @author Wings
 * @since 2023-12-18
 */
@Data
@Schema(name = "字典数据入参")
@Valid
public class DictDataCO {

    @Schema(description = "主键", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @NotEmpty(message = "ID不能为空", groups = EditGroup.class)
    private String id;

    @Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotEmpty(message = "字典类型代码不能为空", groups = {AddGroup.class, EditGroup.class})
    private String dictType;

    @Schema(description = "字典数据代码", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotEmpty(message = "字典数据代码不能为空", groups = {AddGroup.class, EditGroup.class})
    private String dictCode;

    @Schema(description = "字典数据值", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotEmpty(message = "字典数据值不能为空", groups = {AddGroup.class, EditGroup.class})
    private String dictValue;

    @Schema(description = "字典排序", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotEmpty(message = "字典排序不能为空", groups = {AddGroup.class, EditGroup.class})
    private Integer dictSort;

    public static DictDataEntity toAddEntity(DictDataCO dictDataCO) {
        DictDataEntity dictData = new DictDataEntity();
        dictData.setDictType(dictDataCO.getDictType());
        dictData.setDictCode(dictDataCO.getDictCode());
        dictData.setDictValue(dictDataCO.getDictValue());
        dictData.setDictSort(dictDataCO.getDictSort());
        return dictData;
    }

    public static void toEditEntity(DictDataEntity dictData, DictDataCO dictDataCO) {
        dictData.setDictType(dictDataCO.getDictType());
        dictData.setDictCode(dictDataCO.getDictCode());
        dictData.setDictValue(dictDataCO.getDictValue());
        dictData.setDictSort(dictDataCO.getDictSort());
    }
}
